package com.example.myapplication;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Blog implements Serializable {
    private String title;
    private String content;
    private String coverImagePath;
    private long timestamp;

    public Blog(String title, String content, String coverImagePath) {
        this.title = title;
        this.content = content;
        this.coverImagePath = coverImagePath;
        this.timestamp = System.currentTimeMillis();
    }

    // Getters
    public String getTitle() {
        return title;
    }

    public String getContent() {
        return content;
    }

    public String getCoverImagePath() {
        return coverImagePath;
    }

    public long getTimestamp() {
        return timestamp;
    }

    // 获取格式化日期
    public String getFormattedDate() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        return sdf.format(new Date(timestamp));
    }

    // 获取内容摘要
    public String getSummary() {
        return content.length() > 50 ?
                content.substring(0, 50) + "..." :
                content;
    }

    // Setters (如果需要修改字段值)
    public void setTitle(String title) {
        this.title = title;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void setCoverImagePath(String coverImagePath) {
        this.coverImagePath = coverImagePath;
    }
}